package com.fan.leetcode;

import org.junit.jupiter.api.Test;

/**
 * 12. 整数转罗马数字
 *
 * @author zhangFan
 * @since 2021/9/7 下午 9:22
 */
public class Question12 {
    @Test
    void test() {
        System.out.println("intToRoman() = " + intToRoman(1994));
    }

    public String intToRoman(int num) {
        char[] chars = String.valueOf(num).toCharArray();
        int length = chars.length;
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < length; i++) {
            String a = null,b = null,c = null;
            switch (length - i) {
                case 4:
                    a = "M";
                    break;
                case 3:
                    a = "C";
                    b = "D";
                    c = "M";
                    break;
                case 2:
                    a = "X";
                    b = "L";
                    c = "C";
                    break;
                case 1:
                    a = "I";
                    b = "V";
                    c = "X";
                    break;
            }
            switch (chars[i]) {
                case '9':
                    str.append(a);
                    str.append(c);
                    break;
                case '8':
                    str.append(b).append(a).append(a).append(a);
                    break;
                case '7':
                    str.append(b).append(a).append(a);
                    break;
                case '6':
                    str.append(b).append(a);
                    break;
                case '5':
                    str.append(b);
                    break;
                case '4':
                    str.append(a).append(b);
                    break;
                case '3':
                    str.append(a);
                case '2':
                    str.append(a);
                case '1':
                    str.append(a);
            }
        }
        return String.valueOf(str);
    }

}
